#include <cstring>
#include "KCTreeDB.h"

int KCTreeDB::open()
{
	if (db->open(db_path, TreeDB::OWRITER | TreeDB::OCREATE)) {
		return 0;
	}
	return -1;
}

int KCTreeDB::close()
{
	if (db->close()) {
		return 0;
	}
	return -1;
}
	
int KCTreeDB::set(string &key, string *value)
{
	if (db->set(key, *value)) {
		return 0;
	}
	return -1;
}
int KCTreeDB::get(string &key, string *value)
{
	if (db->get(key, value)) {
		return 0;
	} else if (!strcmp(db->error().name(), "no record")) {
		return 1;
	}
	return -1;
}

int KCTreeDB::remove(string &key)
{
	if (db->remove(key)) {
		return 0;
	}
	return -1;
}
